// from book Benmammar ex 3a page 132
public class Compteurs extends Thread {
private String nom = null;
public Compteurs(String n) {
nom=n;
}
public void run () {
for (int i=0; i<10; i++) {
System.out.println(nom + ": "+i);
try {Thread.sleep((long) Math.random()*5000);}
catch(InterruptedException e) { }
}
System.out.println(nom + " finish to count until 10.");
}
public static void main(String[] args) {
Compteurs tA, tB, tC, tD;
tA= new Compteurs("tellerA");
tB= new Compteurs("tellerB");
tC= new Compteurs("tellerC");
tD= new Compteurs("tellerD");
tA.start();
tB.start();
tC.start();
tD.start();
}
}